package ciyuan.Item.SkillBook;

import ciyuan.Item.ItemGroups;
import ciyuan.Item.TypeInterface.SkillBookType;
import ciyuan.Player.Skill.SkillUtils;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;

public class Devote extends SkillBookType {

    public Devote() {
        super(new Properties().tab(ItemGroups.SkillBook));
    }

    @Override
    public void keyDown(PlayerEntity playerEntity) {
        SkillUtils.setSkillColdInterval(playerEntity, this, 25 * 1000);

        playerEntity.setHealth(playerEntity.getHealth() - (playerEntity.getHealth() * 0.3F));
        for (LivingEntity livingentity : playerEntity.level.getEntitiesOfClass(LivingEntity.class, playerEntity.getBoundingBox().inflate(6.0D, 6.0D, 6.0D))) {
            if (livingentity instanceof PlayerEntity && playerEntity.distanceToSqr(livingentity) < 36.0D) {
                for (EffectInstance effectInstance : livingentity.getActiveEffects()) {
                    if (!effectInstance.getEffect().isBeneficial()) {
                        livingentity.removeEffect(effectInstance.getEffect());
                    }
                }
            }
        }

        SkillUtils.saveSkillCastTime(playerEntity,this);
    }

    @Override
    public String getSkillCastName() {
        return "Devote";
    }

    @Override
    public ITextComponent getSkillDescription() {
        return new TranslationTextComponent("ciyuan.skill.desc.14");
    }

    @Override
    public ITextComponent getSkillName() {
        return new TranslationTextComponent("ciyuan.skill.name.14");
    }
}
